home *** CD-ROM | disk | FTP | other *** search
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = 0 'False
- END
- Attribute VB_Name = "cDAOCommon"
- Attribute VB_Creatable = True
- Attribute VB_Exposed = True
- '|=============================================|
- '| Class : cDAOCommon | |
- '| Purpose : This Class Contains Common |
- '| DAO calls based on EasyDAO |
- '| Date : 2/8/97 |
- '| Author : Lee D. Johnson |
- '| jb32@ix.netcom.com |
- '| Lee@techknow-inc.com |
- '| pitty on IRC |
- '| Version : 1.1 |
- '|=============================================|
- '|=============================================|
- '| NOTE : |
- '| to use this class you must first Dim the |
- '| class in either a Module or Forms |
- '| Declarations. To do this use something |
- '| like this : |
- '| Public ClsDAO As New cDAOCommon |
- '| Before You use this Class you must now set |
- '| the name of your Data Control to the Class |
- '| this is done like this : |
- '| ClsDAO.SetDao data1 |
- '|=============================================|
- Option Explicit
- '|=============================================|
- '| |
- '| Private Variables |
- '| |
- '|=============================================|
- 'Name for the Data Control which the
- 'User must initialize
- Private pstrDataSource As Data
- 'Tells if a Data Control is passed to it
- Private bDataNameSet As Boolean
- 'Tells the Class if It Has Authority to SaveNew
- 'Or the CancelNew
- Private bSavingData As Boolean
- 'Sets Authority for Find Next
- Private bFindNext As Boolean
- 'Declares for Message Boxes
- Private Msg
- Private Style
- Private Title
- Private Response
-
-
- Public Sub AddNewData()
- 'See if Data Control is set
- IsDataSet
- 'Add New Record Ensuring the record is at
- 'the end of the table
- pstrDataSource.Recordset.MoveLast
- pstrDataSource.Recordset.AddNew
- 'Disable the data control while new record
- pstrDataSource.Enabled = False
- 'Setting Allows CancelNew and AddNew to work
- bSavingData = True
- End Sub
-
- Public Sub DeleteRecord()
- 'Check to see if the Data Control has been set
- IsDataSet
- 'Check to see that there are at least 3 records
- If pstrDataSource.Recordset.RecordCount < 3 Then
- 'Refuse Deletion for last 2 records
- Msg = "You Cannot Delete the last 2 records"
- MsgBox Msg
- Exit Sub
- End If
- 'Ask the User if they are sure they want to delete
- Msg = "You are about to permanetly remove this Record"
- Title = "Delete Record"
- Style = vbOKCancel + vbExclamation
- Response = MsgBox(Msg, Style, Title)
- If Response = vbCancel Then Exit Sub
- 'If User says yes then delete the record
- pstrDataSource.Recordset.Delete
- pstrDataSource.Recordset.MoveFirst
- End Sub
-
- Public Function FindData(strField As String, strCriteria As String) As Boolean
- 'strField is the field that the data is stored in
- 'strCriteria is the Criteria asked
- 'Check to see if the Data Control has been set
- IsDataSet
- 'Searches For the first Instance depending on the criteria
- pstrDataSource.Recordset.FindFirst strField & "= '" & strCriteria & "'"
- 'If there is no match Tell user and set flags
- If pstrDataSource.Recordset.NoMatch Then
- MsgBox "Record Not Found"
- FindData = False
- bFindNext = False
- Else
- 'Found Criteria and setting FindNext Flags
- FindData = True
- bFindNext = True
- End If
- End Function
-
- Public Function FindNextData(strField As String, strCriteria As String) As Boolean
- 'Check to see if the Data Control has been set
- IsDataSet
- 'Tell User they need to use FindFirst First
- If bFindNext = False Then
- MsgBox ("You Cannot Use FindNext unless you use FindFirst First")
- Exit Function
- End If
- 'Search the data object for the criteria
- pstrDataSource.Recordset.FindNext strField & "= '" & strCriteria & "'"
- 'Tell user no match and set Flags
- If pstrDataSource.Recordset.NoMatch Then
- MsgBox "Record Not Found"
- FindNextData = False
- bFindNext = False
- Else
- 'Set FindNext Flags
- FindNextData = True
- bFindNext = True
- End If
- End Function
-
- Private Sub IsDataSet()
- 'Check to see if the data control has been set
- 'If the Data control is not set the programmer is told
- 'and the application ends
- If bDataNameSet = False Then
- 'If Data Control Name Has Not been Initializied
- MsgBox "You Must Use SetDAO before calling this"
- End
- End If
- 'Note This should never happen on the users end
- 'It occurs if the object was itialized without providing
- 'a data object to pass. If this error happened please see
- 'references in Public Sub SetDao(DataSource As Object)
- End Sub
-
- Public Sub SaveNewData()
- 'Check to see if the Data Control has been set
- IsDataSet
- If bSavingData = False Then Exit Sub
- bSavingData = False
- 'Check to see if Data Control has been set
- IsDataSet
- 'Set up simple Error Handler
- On Error GoTo Datasave
- 'Save the data by moving to the first record
- 'and refreshing the data
- pstrDataSource.Enabled = True
- pstrDataSource.Recordset.MoveFirst
- pstrDataSource.Refresh
- Exit Sub
- 'Tell User there was an error saving
- Datasave:
- MsgBox "There was an Error saving the record : " & Chr(13) & Err.Description
- bSavingData = True
- End Sub
-
- Public Sub CancelNewData()
- 'Cancel Add New
- 'Check to see if the Data Control has been set
- IsDataSet
- 'Ensure Class has the Authority to run this
- If Not bSavingData Then Exit Sub
- 'Refresh the data, hereby removing what the
- 'Users had in thier textboxes
- pstrDataSource.Refresh
- 'Disable Authority
- bSavingData = False
- 'Enable Data Object for user input
- pstrDataSource.Enabled = True
- End Sub
-
-
- Public Sub SetDao(DataSource As Object)
- 'Set's the Data Controls Name
- 'This is a must before using other calls
- Set pstrDataSource = DataSource
- bDataNameSet = True
- End Sub
-
- Private Sub Class_Initialize()
- bSavingData = False
- bFindNext = False
- bDataNameSet = False
- End Sub
-
-
-